package com.greate.rabbit.springbootrabbitmqdemo.provide;

import jdk.nashorn.internal.objects.annotations.Setter;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *
 *
 *  </div>
 *
 * @author zhangshun
 * @date 2021/2/4 11:14
 */
@Component
public class Producer {

    private RabbitTemplate rabbitTemplate;

    @Autowired
    public void setRabbitTemplate(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void produceHello(){
        String message =  new Date() + "Beijing";
        System.out.println("生产者生产消息=====" + message);
        rabbitTemplate.convertAndSend("hello",  message);
    }


    public void produceDirect(){
        String message = "test_direct";
        System.out.println("生产者生产消息=====" + message);
        rabbitTemplate.convertAndSend("logs_direct","info",message);
    }

    public void produceFanout(){
        String message = "test_fanout";
        System.out.println("生产者生产消息=====" + message);
        rabbitTemplate.convertAndSend("logs","info",message);
    }

    public void produceTopic(){
        String message = "test_topic";
        System.out.println("生产者生产消息=====" + message);
        rabbitTemplate.convertAndSend("logs","user.save",message);
    }

}
